package com.example.newspapersmanageos.Service;

import com.example.newspapersmanageos.Entity.Page;
import com.example.newspapersmanageos.Entity.User;
import com.example.newspapersmanageos.Mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OperationService {
    @Autowired
    UserMapper userMapper;

    //删除用户
    public boolean deleteUserById(int id) {
        boolean b = true;
        int i = userMapper.deleteUserById(id);
        b = i == 1 ? true : false;
        return b;
    }

    //根据用户名查询用户
    public Page<User> searchUserByName(String name, int pageNum, int pageSize) {
        Page<User> page = new Page(pageNum, pageSize);
        int count = userMapper.countByUserName(name);
        int parameter = (pageNum-1)*pageSize;
        List<User> u = userMapper.searchUserByName(name, parameter, pageSize);
        page.setList(u);
        page.setTotalCount(count);
        return page;
    }

    //根据id修改用户删除用户
    public boolean searchUserById(int id) {
        boolean b = true;
        int i = userMapper.deleteUserById(id);
        b = i == 1 ? true : false;
        return b;
    }

}
